import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '../layout/index-view.vue'

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/user/login-view.vue'),
      meta: {
        title: '登录注册',
        disable: false,
      }
    },
    {
      path: '/404',
      name: '404',
      component: () => import('@/views/error/404.vue'),
      meta: {
        title: '404',
        disable: false,
      },
    },
    {
      path: '/401',
      name: '401',
      component: () => import('@/views/error/401.vue'),
      meta: {
        title: '401',
        disable: false,
      },
    },
    {
      path: '/:pathMatch(.*)*',
      redirect: '/404',
    },
    {
      path: '/',
      name: 'index',
      component: Layout,
      redirect: "index",
      meta: {
        title: '首页',
        disable: true,
        icon: "icon-shouye",
        lang: "Home"
      },
      children: [
        {
          path: '/',
          name: 'index',
          component: () => import('@/views/index/index-view.vue'),
          meta: {
            title: "首页",
            disable: false
          },
        },
      ]
    },
    {
      path: '/order-pool',
      name: 'order-pool',
      component: Layout,
      redirect: "/order-pool/index",
      meta: {
        title: "订单池",
        disable: true,
        icon: "icon-zidian",
      },
      children: [
        {
          path: '/order-pool/index',
          name: 'order-pool',
          component: () => import('@/views/order-pool/index-view.vue'),
          meta: {
            title: "订单池",
            disable: true
          },
        },
      ]
    },
    {
      path: '/order-wait-ticket',
      name: 'order-wait-ticket',
      component: Layout,
      redirect: "/order-wait-ticket/index",
      meta: {
        title: "待出票",
        disable: true,
        icon: "icon-zidian",
      },
      children: [
        {
          path: '/order-wait-ticket/index',
          name: 'order-wait-ticket',
          component: () => import('@/views/order-wait-ticket/index-view.vue'),
          meta: {
            title: "待出票",
            disable: true
          },
        },
      ]
    },
    {
      path: '/my-order',
      name: 'my-order',
      component: Layout,
      redirect: "/my-order/index",
      meta: {
        title: "我的订单",
        disable: true,
        icon: "icon-zidian",
      },
      children: [
        {
          path: '/my-order/index',
          name: 'my-order',
          component: () => import('@/views/my-order/index-view.vue'),
          meta: {
            title: "我的订单",
            disable: true
          },
        },
      ]
    },
    {
      path: '/account',
      name: 'account',
      component: Layout,
      redirect: "/user/account",
      meta: {
        title: "我的账户",
        disable: true,
        icon: "icon-zidian",
      },
      children: [
        {
          path: '/user/account',
          name: 'account',
          component: () => import('@/views/user/account-view.vue'),
          meta: {
            title: "我的账户",
            disable: true
          },
        },
      ]
    },
    {
      path: '/pool-config',
      name: 'pool-config',
      component: Layout,
      redirect: "/pool-config/index",
      meta: {
        title: "自动报价设置",
        disable: true,
        icon: "icon-zidian",
      },
      children: [
        {
          path: '/pool-config/index',
          name: 'pool-config',
          component: () => import('@/views/pool-config/index-view.vue'),
          meta: {
            title: "自动报价设置",
            disable: true
          },
        },
      ]
    },
    {
      path: '/check-config',
      name: 'check-config',
      component: Layout,
      redirect: "/check-config/index",
      meta: {
        title: "自动报价校验",
        disable: true,
        icon: "icon-zidian",
      },
      children: [
        {
          path: '/check-config/index',
          name: 'check-config',
          component: () => import('@/views/check-config/index-view.vue'),
          meta: {
            title: "自动报价校验",
            disable: true
          },
        },
      ]
    },
  ],
  // 控制滚动条的位置
  scrollBehavior() {
    return {
      left: 0,
      top: 0
    }
  }
})
// router.beforeEach((to, from, next) => {
//   const { loginStatus } = useUserInfoStore();
//   // 登录页面且未登录。跳转到登录页
//   if (to.path === '/login') return next();
//   // 没有登录，重定向到登录页面
//   if (!loginStatus.state) return next(`/login?redirect=${to.path}`);
//   next();
// })

export default router
